package org.leon.mybatis.mapper;

import org.apache.ibatis.jdbc.SQL;
import org.leon.mybatis.domain.User;

/**
 * Created by HuGuodong on 2017/5/3.
 */
public class UserDynaSqlProvider {
    public String updateUser(User user){
        return new SQL(){
            {
                UPDATE("mybatis_user");
                if(user.getName()!=null){
                    SET("name=#{name}");
                }
                if(user.getSex()!=null){
                    SET("sex=#{sex}");
                }
                if(user.getAge()!=null){
                    SET("age=#{age}");
                }
                WHERE("id=#{id}");
            }
        }.toString();
    }
}
